package com.brush.web.controller;

import com.brush.app.domain.req.Ad.add.AppAdvertiseAddReq;
import com.brush.app.domain.req.Ad.edit.AppAdEditReq;
import com.brush.app.domain.req.Ad.query.AppAdQueryReq;
import com.brush.app.domain.resp.Ad.AppAdResp;
import com.brush.app.service.AppAdService;
import com.brush.common.core.controller.BaseController;
import com.brush.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "后台-轮播广告管理")
@RestController
@RequestMapping(value = "/admin/brush/swiper")
public class AdminAdController extends BaseController {
    @Autowired
    private AppAdService appAdService;

    /*
     * 首先做分页查询
     * */
    @PreAuthorize("@ss.hasPermi('app:advs:list')")
    @ApiOperation(value = "advertise分页查询")
    @GetMapping("/list")
    public R<PageInfo<AppAdResp>> pagination(AppAdQueryReq req) {
        PageInfo<AppAdResp> page = this.appAdService.paginationQuery(req);
        return R.ok(page);
    }

    /*
     * 根据id查询
     * */
    @PreAuthorize("@ss.hasPermi('app:advs:query')")
    @ApiOperation(value = "根据id查询广告")
    @GetMapping("/{id}")
    public R<AppAdResp> findById(@PathVariable(value = "id") Long id) {
        AppAdResp resp = this.appAdService.findById(id);
        return R.ok(resp);
    }

    /*
     * 新增
     * */
    @PreAuthorize("@ss.hasPermi('app.advs.add')")
    @ApiOperation(value = "新增")
    @PostMapping
    public R add(@RequestBody @Valid AppAdvertiseAddReq req) {
        boolean res = this.appAdService.add(req);
        return super.isSuccess(res);
    }
    /*
    * 编辑
    * */
    @PreAuthorize("@ss.hasPermi('app:advs:edit')")
    @ApiOperation(value = "编辑")
    @PutMapping
    public R edit(@RequestBody @Valid AppAdEditReq req){
        boolean res =this.appAdService.edit(req);
        return super.isSuccess(res);
    }

    /*
    * 删除
    * */
    @PreAuthorize("@ss.hasPermi('app:advs:remove')")
    @ApiOperation(value = "删除")
    @DeleteMapping("/{ids}")
    public R delete(@PathVariable(value = "ids") Long[] ids){
        boolean res = this.appAdService.deleteById(ids);
        return super.isSuccess(res);
    }
}
